<template>
  <div class="app-container">

    <u-page title="会员RFM">
      <el-alert
        title="查询说明"
        type="success"
        description="1.点击查询查询当月所有会员消费数据 2.该数据统计去年月初至本月月初月结时会员数据"
        :closable="false"
      />
      <u-filtered>
        <el-form>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
            <el-button type="primary" icon="el-icon-download" @click="handleDownload">导出</el-button>
          </el-form-item>
        </el-form>
      </u-filtered>

      <u-table
        :data="list"
        :loading="listLoading"
        :options="listOptions"
        :columns="columns"
        :pagination.sync="listQuery"
        :fetch="hdlList"
        @selection-change="hdlSelectChange"
      />

    </u-page>
  </div>
</template>
<script>
export default {
  data() {
    return {
      api: this.$u.api.DataPlanningvipconsumedata,
      // 表格
      columns: [
        {
          prop: 'vipno',
          label: '卡号',
          width: '160'
        },
        {
          prop: 'intervaldays',
          label: '间隔天数'
        },
        {
          prop: 'paiddays',
          label: '消费天数'
        },
        {
          prop: 'dailyamount',
          label: '日均消费'
        },
        {
          prop: 'firstdept',
          label: '消费频次第一专柜'
        },
        {
          prop: 'secenddept',
          label: '消费频次第二专柜'
        },
        {
          prop: 'thirddept',
          label: '消费频次第三专柜'
        },
        {
          prop: 'maxamount',
          label: '单笔最高消费'
        },
        {
          prop: 'telphone',
          label: '手机号码'
        },
        {
          prop: 'openid',
          label: 'openid'
        },
        {
          prop: 'membername',
          label: '姓名'
        },
        {
          prop: 'sex',
          label: '性别'
        },
        {
          prop: 'age',
          label: '年龄'
        },
        {
          prop: 'memberlevel',
          label: '卡别'
        }
      ],
      list: [],
      listLoading: false,
      listOptions: {
        mutiSelect: false,
        stripe: true
      },
      listQuery: {
        page: 1,
        pageSize: 20,
        totalCount: 1
      }
    }
  },
  created() {},
  mounted() {},
  methods: {
    // 搜索事件
    handleFilter() {
      this.listQuery.page = 1
      this.hdlFilter()
    },
    /**
     * 查询事件
     */
    hdlFilter() {
      this.listQuery.page = 1
      this.hdlList()
    },
    /**
     * 获取列表数据
     */
    hdlList() {
      const self = this
      // 打开加载状态
      self.listLoading = true
      self.api.list(self.listQuery).then(res => {
        // 获取分页列表数据
        self.list = res.data.list
        // fix:修复ID重复的问题,设置table表格key值必须唯一
        self.list.forEach((item, index) => {
          self.list[index].index = index
        })
        // 获取分页数据,总页数
        self.listQuery.totalCount = res.data.totalCount
        // 关闭加载状态
        setTimeout(() => {
          self.listLoading = false
        }, 0.5 * 1000)
      })
    },
    // 导出数据
    handleDownload() {
      // 复制值
      const list = this.$u.deepClone(this.list)
      // 业务数据处理
      // 表头&表数据
      const tHeader = ['卡号', '间隔天数', '消费天数', '日均消费', '消费频次第一专柜', '消费频次第二专柜', '消费频次第三专柜', '单笔最高消费',
        '手机号码', 'openid', '姓名', '性别', '年龄', '卡别']
      const filterVal = ['vipno', 'intervaldays', 'paiddays', 'dailyamount', 'firstdept', 'secenddept', 'thirddept', 'maxamount',
        'telphone', 'openid', 'membername', 'sex', 'age', 'memberlevel']
      const data = list.map(v => filterVal.map(j => { return v[j] }))
      const tiltle = this.lastyearmonth + '会员RFM'
      this.$u.exports.excel(tiltle, tHeader, data)
    }
  }
}
</script>
<style>
.el-select .el-input {
  width: 220px;
}
</style>
<style lang="scss" scoped>
.app-container{
  .item >>> .el-form-item__content {
    display: flex;
  }
  .status {
    ::v-deep{
      .el-input{
        width: 140px;
      }
    }
  }
  ::v-deep{
    .el-table-expand {
      font-size: 0;

      label {
        width: 90px;
        color: #99a9bf;
        font-size: 12px;
      }

      .el-form-item{
        margin-bottom: 2px;
        margin-right: 0;
        vertical-align: top;
      }

      .el-form-item__content {
        margin-right: 0;
        margin-bottom: 0;
        font-size: 12px;
        display: inline-block;
        vertical-align: top;
        position: relative;
      }
    }
  }
}
</style>
